import { GlobalContainer } from '@/RoomDesign/common/GlobalContainer'
import type { FloorService } from '@/RoomDesign/domain/service/FloorService'
import type { TestService } from '@/RoomDesign/domain/service/TestService'
import type { ZoneService } from '@/RoomDesign/domain/service/ZoneService'
import { Point3D } from './dto/Point3D'
import { Point2D } from './dto/Point2D'
import { ThreeRenderService } from './render-support/ThreeRenderService'

/**
 * 房屋编辑控制器：
 * 1、区域绘制功能
 */
export class House3DDesignAppService {
  private _renderService = ThreeRenderService.getInstance()

  private _testBo: TestService = GlobalContainer.doServiceContainer.testService
  private _zoneService: ZoneService = GlobalContainer.doServiceContainer.zoneService
  private _floorService: FloorService = GlobalContainer.doServiceContainer.floorService

  constructor() {}

  private get page() {
    return GlobalContainer.doServiceContainer.designPageService.getPage()
  }

  public createZone(point2DList: Point2D[]) {
    const zone = this._zoneService.createZone(point2DList)
    const floor = this._floorService.createFloor(point2DList, new Point3D(0, 0, 0))
    floor.zone = zone

    this.page.zoneList.push(zone)
    this.page.floorList.push(floor)
    // 调用渲染服务生成地板模型
    this._renderService.createMeshAndAddToScene(floor)
  }

  public testTextureAlign() {
    GlobalContainer.doServiceContainer.testService.textureTest()
    this._testBo.testTextureAlign_wall(GlobalContainer.threeSceneController.scene)
  }
}
